Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
¿Por qué no empuja el elemento al estado de matriz "tareas"?

Estoy tratando de crear una aplicación de tareas pendientes en React. Actualmente estoy tratando de imprimir la entrada cuando presiono el botón +, pero no funciona. ¿Alguien puede ayudar a verificar mi sintaxis?

 import React from 'react'; import './App.css'; class App extends React.Component { constructor(){ super(); this.state = { value: '', tasks: [] }; this.handleChange = this.handleChange.bind(this) this.addItem = this.addItem.bind(this) } handleChange(event) { this.setState({ value: event.target.value }) } addItem(){ this.state.tasks.push(this.state.value) } render(){ return( <div> <input type="text" value={this.state.value} onChange={this.handleChange}></input> <button onClick={this.addItem}>+</button> <button>-</button> <h1>{this.state.tasks}</h1> </div> ) } } export default App;

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Para cambiar el estado, debe usar this.setState . Consulte https://reactjs.org/docs/state-and-lifecycle.html#do-not-modify-state-directly . Leer la documentación de React puede ahorrarle mucho tiempo en general.

about 4 years ago · Juan Pablo Isaza Report

0

Necesitas establecer la tarea State

 addItem() { const newTask = [this.state.value, ...this.state.tasks]; this.setState({ tasks: newTask }); this.setState({ value: "" }); }

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report

0

¡Modificar el estado directamente no es la forma correcta!

en su lugar, use setState:

 this.setState({ tasks: this.state.tasks.concat(this.state.value) })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!